//张
//搜索页
<template>
  <div class="search_page_box">
    <div class="top_block">
      <div class="nav_box">
        <li
          ref="searchNav"
          v-for="(item, id) in nav_list"
          :key="id"
          @click="nav_router(id), get_nav_left($event)"
        >
          {{ item.name }}
        </li>
      </div>
    </div>
    <div class="bottom_block">
      <div class="scrollbar" ref="scrollbar"></div>
      <div class="router_box">
        <router-view
          @init="initBar()"
          :key="$route.fullPath"
        ></router-view>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "search_page",
  data() {
    return {
      nav_list: [
        { name: "歌曲" },
        { name: "专辑" },
        { name: "歌单" },
        { name: "用户" },
      ],
    };
  },
  mounted() {},
  watch: {},
  methods: {
    nav_router(index) {
      switch (index) {
        case 0:
          this.$router.push({
            path: "/search_music",
            query: {
              keyword: this.$route.query.keyword,
            },
          });
          break;
        case 1:
          this.$router.push({
            path: "/search_album",
            query: {
              keyword: this.$route.query.keyword,
            },
          });
          break;
        case 2:
          this.$router.push({
            path: "/search_playlist",
            query: {
              keyword: this.$route.query.keyword,
            },
          });
          break;
        case 3:
          this.$router.push({
            path: "/search_user",
            query: {
              keyword: this.$route.query.keyword,
            },
          });
          break;
      }
    },
    get_nav_left(e) {
      var lxl = e.target.offsetLeft - this.$refs.scrollbar.offsetLeft + "px";
      this.$refs.scrollbar.style.transform = "translateX(" + lxl + ")";
    },
    initBar() {
      let barLeft = -this.$refs.scrollbar.offsetLeft + "px";
      this.$refs.scrollbar.style.transform = "translateX(" + barLeft + ")";
    },
  },
};
</script>

<style scoped>
.search_page_box {
  width: 100%;
  height: 876px;
  margin: 0 auto;
}
.top_block {
  display: flex;
  justify-content: center;
  width: 100%;
  height: 62px;
  background: #21262c;
}

.nav_box {
  display: flex;
  width: 1314px;
  position: relative;
}
.nav_box li {
  width: 161px;
  text-align: center;
  line-height: 62px;
  font-size: 18px;
  font-family: Microsoft YaHei UI;
  font-weight: 300;
  color: #ffffff;
}
.nav_box li:hover {
  cursor: pointer;
}
.router_box {
  width: 1324px;
  margin: 0 auto;
}
.bottom_block {
  width: 1314px;
  margin: 0 auto;
  height: 913px;
  background: #ffffff;
  box-shadow: 0px 2px 27px 0px rgba(0, 0, 0, 0.47);
  position: relative;
}
.scrollbar {
  position: absolute;
  width: 161px;
  height: 10px;
  background: #659274;
  top: 0px;
  left: 0px;
  transition: all 0.3s;
}
</style>